package com.example.tuShare.tuShareController;

import com.example.tuShare.ApiResponse;
import com.example.tuShare.DTO.FinaIndicatorRequest;
import com.example.tuShare.DTO.TradeDay;
import com.example.tuShare.tuShareService.TushareService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tuShare")
public class TushareController {

    @Autowired
    private TushareService tushareFinaIndicator;

    //财务指标数据查询
    @PostMapping("/finalndicator")
    public ApiResponse tuShareFinalndicator(@RequestBody FinaIndicatorRequest finaIndicatorRequest, @RequestHeader("token") String token) {
        ApiResponse apiResponse = tushareFinaIndicator.callFinaIndicator(finaIndicatorRequest, token);
        return apiResponse;
    }

    //循环财务指标数据查询
    @PostMapping("/cycleFinalndicator")
    public void tuShareFinalndicator(@RequestHeader("token") String token) {
        tushareFinaIndicator.callFinaIndicator(token);
    }

    //获取全部股票每日重要的基本面指标，可用于选股分析、报表展示等。
    @PostMapping("/dailyBasic")
    public ApiResponse tuShareDailyBasic(@RequestBody FinaIndicatorRequest finaIndicatorRequest, @RequestHeader("token") String token) {
        ApiResponse apiResponse = tushareFinaIndicator.callDailyBasic(finaIndicatorRequest, token);
        return apiResponse;
    }

    //循环获取全部股票每日重要的基本面指标，可用于选股分析、报表展示等。
    @PostMapping("/cycleDailyBasic")
    public void tuShareDailyBasic(@RequestHeader("token") String token) {
        tushareFinaIndicator.callDailyBasic(token);
    }

    //获取csv文件,处理数据并导出输出表
    @PostMapping("/getCsvAndOutput")
    public ApiResponse getCsvAndOutput(@RequestBody FinaIndicatorRequest finaIndicatorRequest) {
        ApiResponse apiResponse = tushareFinaIndicator.getCsvAndOutput(finaIndicatorRequest);
        return apiResponse;
    }

    //获取交易日
    @PostMapping("/getTradeDate")
    public List<TradeDay> getTradeDate(@RequestBody FinaIndicatorRequest finaIndicatorRequest, @RequestHeader("token") String token) {
        return tushareFinaIndicator.getTradeDate(finaIndicatorRequest.getStartDate(), finaIndicatorRequest.getEndDate(), token);
    }

    //分红送股
    @PostMapping("/dividend")
    public ApiResponse dividend(@RequestBody FinaIndicatorRequest finaIndicatorRequest, @RequestHeader("token") String token) {
        return tushareFinaIndicator.dividend(finaIndicatorRequest, token);
    }

    //循环获取所有分红送股
    @SneakyThrows
    @PostMapping("/cycleDividend")
    public void cycleDividend(@RequestHeader("token") String token) {
        tushareFinaIndicator.dividend(token);
    }

    //获取所有股票的代码
    @PostMapping("/getTsCode")
    public ApiResponse getTsCode(@RequestHeader("token") String token) {
        return tushareFinaIndicator.getTsCode(token);
    }
}
